package huang.teamwork15;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TransferRecordsDao {
		BaseDao bd=new BaseDao();
		Connection con=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		public void close() throws SQLException{
			if(rs!=null){
				rs.close();
			}
			if(ps!=null){
				ps.close();
			}
			if(con!=null){
				con.close();
			}
		}
		public TransferRecords selectMessageByremitter(String remitter) throws SQLException{
			con=bd.getCon();
			String sql="select *from transferrescords where remitter=?";
			ps=con.prepareStatement(sql);
			ps.setString(1, remitter);
			rs=ps.executeQuery();
			String transferTime=null;
			String transferFund=null;
			String payee=null;
			while(rs.next()){
				transferTime=rs.getString("transferTime");
				transferFund=rs.getString("transferFund");
				payee=rs.getString("payee");
			}
			close();
			TransferRecords tr =new TransferRecords(transferTime,transferFund,remitter,payee);
			return tr;
			
		}	
		public static void main(String[] args) throws SQLException {
			TransferRecordsDao td =new TransferRecordsDao();
			TransferRecords tr=new TransferRecords();
			tr=td.selectMessageByremitter("huang");
			System.out.println(tr.getPayee());
		}
}
